<template>
  <div>
    <van-row>
      <van-col offset="1">
        <h3 style="text-align: center;">各位同学可以在本系统上答题或者进行练习。有志者事竟成！</h3>
      </van-col>
    </van-row>
      <router-view></router-view>
    </div>
</template>

<script>
import { Dialog } from 'vant'
import {baseUrl} from '../constants'

export default {
  name: 'questions',
  data () {
    return {
      area: { maxHeight: 300, minHeight: 100 },
      isStudy:false,
      routeKey:'',
    }
  },
  mounted(){
    if(/study/g.test(this.$route.path)){
       this.isStudy=true;
       this.routeKey='study'
     }else {
      this.routeKey='test'
    }
    this.$store.commit('set_study',this.isStudy);
  },
  methods: {
    toggle (index) {
      this.$refs.checkboxes[index].toggle()
    },
    back(){
        if(this.currentIndex==1){
          this.$dialog.alert({
            message:'当前为第一页，请点击下一页'
          })
          return;
        }else {
          this.currentIndex-=1;
          this.currentPaperList = this.paperList.slice((this.currentIndex-1)*3,this.currentIndex*3);
          return;
        }
    },
    next(){
        if(this.currentIndex==4){
          //答案提交
          if(this.answers.length==10){
              let data1={type:this.paperKey,answers:this.answers};
              this.axios.post(baseUrl.serverUrl+'/user/answer?id='+this.userid,{content:JSON.stringify(data1)}).then(res=>{
                 if(res.data.status==1){
                   this.$dialog.alert({
                     message:'调查提交成功,谢谢您的配合'
                   })
                 }else {
                   this.$dialog.alert({
                     message:'提交失败请重试'
                   })
                 }
              })
               //向服务器提交
          }else {
            this.$dialog.alert({
              message:'您还有未填写的选项请您检查后再提交'
            })
            return;
          }
        }else {
          this.currentIndex+=1;
          this.currentPaperList = this.paperList.slice((this.currentIndex-1)*3,this.currentIndex*3);
          return;
        }
    },
  }
}
</script>

<style scoped>
</style>
